<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <!-- 常见的this指向 -->
  <script>

    // 1.对象中的this指向上层对象
    var car = {
      name: "奔驰",
      run: function () {
        console.log(this.name) //this--->car
      },
      room: {
        name: "高配",
        say: function () {
          console.log(this.name)//this-->room
        }
      }
    }
    car.run()
    car.room.say()
    // 2 纯粹 的函数中this指向window
    var name = "今天星期四"
    function say() {
      console.log(this.name) //this---window
    }
    say()
    var run = function () { }
    setInterval(function () {
      console.log(this.name) //this---window
    }, 2000)
    //3 构造函数中的this指向 当前实例化对象
    function Person(name, age) {
      this.name = name;
      this.age = age;
      this.run = function () {
        console.log(this.name)
      }
    }
    var telangpu = new Person("特朗普", "74");
    telangpu.run()
    // 4 事件函数中的this指向
    // lis[i].onclick = function () {
    //   // this---当前点击li
    // }
  </script>
</body>

</html>